package org.springframework.remoting.jsonrpc;

import java.io.IOException;
import java.io.Writer;

public class DojoAjaxHandler implements AJAXHandler {
  public void writeAjaxCall(Writer writer) throws IOException {
    writer.write(" dojo.require(\"dojo.io.*\");\n");
    writer.write("\n");
    writer.write("\n");
    writer.write("var AjaxCall = Class.create();\n");
    writer.write("AjaxCall.prototype =\n");
    writer.write("{\n");
    writer.write("   makeCall :function()\n");
    writer.write("   {\n");
    writer.write("     this.options.mimetype = 'text/json';\n");
    writer.write("     this.options.method = 'post';\n");
    writer.write("     this.options.url = 'remoting/AccountService';\n");
    writer.write("     return dojo.io.bind (this.options);\n");
    writer.write("    },\n");
    writer.write("    setBody : function(json)\n");
    writer.write("    {\n");
    writer.write("      this.options.postContent = json;\n");
    writer.write("    }\n");
    writer.write(" };\n");
    writer.write(" Object.extend(AjaxCall.prototype, AjaxInterface.prototype);\n");

  }
  
  public void writeToJson(Writer writer) throws IOException {
    writer.write(" function toJSON(obj){\n");
    writer.write("  return dojo.toJson(obj);");
    writer.write("}\n");
    
  }
}
